package com.fy.fyzf.presenter;

import com.fy.fyzf.api.SubscriberCallBack;
import com.fy.fyzf.base.BaseApp;
import com.fy.fyzf.base.BasePresenter;
import com.fy.fyzf.bean.BaseData;
import com.fy.fyzf.bean.CommonSearchBean;
import com.fy.fyzf.bean.HousesListBean;
import com.fy.fyzf.bean.RecordBean;
import com.fy.fyzf.bean.UserInfoBean;
import com.fy.fyzf.utils.SPUtils;
import com.fy.fyzf.view.SelfInfoCallBack;

import java.util.List;

import okhttp3.MultipartBody;

public class SelfPresenter extends BasePresenter<SelfInfoCallBack> {

    public SelfPresenter(SelfInfoCallBack view) {
        super(view);
    }

    public void getSelfInfo(){
        addSubscription(mApiService.getUserInfo(0), new SubscriberCallBack<BaseData<UserInfoBean>>(mView,false) {
            @Override
            protected void onSuccess(BaseData<UserInfoBean> response) {
                mView.getSelfInfoSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }


    public void upLoadImg(MultipartBody.Part body){
        addSubscription(mApiService.uploadImg(body), new SubscriberCallBack<BaseData>(mView,true) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.upLoadImgSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void updataSelfInfo(String userPortrait,int sex,String phone,String joinTime,String userCard,String userAddress,String userHousehold){
        String name = SPUtils.getInstance(BaseApp.getContext()).getString("name", "");
        addSubscription(mApiService.saveUserInfo(userPortrait, sex, phone, joinTime, userCard, userAddress, userHousehold,name), new SubscriberCallBack<BaseData>(mView,true) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.updataSlefInfoSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void getMsgCount(){
        addSubscription(mApiService.getMsgCount(null), new SubscriberCallBack<BaseData>(mView,false) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.getMsgCountSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void setAllRead(){
        addSubscription(mApiService.setAllRead(0), new SubscriberCallBack<BaseData>(mView,false) {
            @Override
            protected void onSuccess(BaseData response) {

            }

            @Override
            protected void onError() {

            }

            @Override
            public void onNext(BaseData o) {

            }
        });
    }

    public void modifPwd(String old,String newPwd){
        addSubscription(mApiService.changePassWord(old, newPwd), new SubscriberCallBack<BaseData>(mView,true) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.changePwdSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void getChangeMsg(){
        addSubscription(mApiService.listExchangeDetails(), new SubscriberCallBack<BaseData<List<RecordBean>>>(mView,false) {
            @Override
            protected void onSuccess(BaseData<List<RecordBean>> response) {
                mView.getChangeMsgSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void getMyHousing(CommonSearchBean commonSearchBean){
        addSubscription(mApiService.myHousingList(commonSearchBean), new SubscriberCallBack<BaseData<HousesListBean>>(mView,true) {
            @Override
            protected void onSuccess(BaseData<HousesListBean> response) {
                mView.getMyHousingSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }
}
